<?php
/**
 * Created by PhpStorm.
 * User: liuhong
 * Date: 2018/11/27
 * Time: 下午3:39
 */

namespace Common\Service;


class ShareService extends BaseService
{
    protected $shareModel;
    protected $shareTypeModel;

    public function __construct()
    {
        $this->shareModel=M('share');
        $this->shareTypeModel=M('sharetype');
    }


    /**
     * 查询出列表信息
     * @param $where
     * @param $page
     * @param int $pagenum
     * @return mixed
     */
    public function queryListInfo($where,$page,$pagenum=20){
       return $this->shareModel
            ->where($where)
            ->page($page,$pagenum)
            ->order('ord asc,id desc')
            ->select();
    }

    /**
     * 查询详细信息
     * @param $where
     * @return mixed
     */
    public function findDetail($where){
        return $this->shareModel->where($where)->find();
    }


    /**
     * 新增列表
     * @param $add
     * @return mixed
     */
    public function addInfo($add){
        return $this->shareModel->add($add);
    }

    /** 删除
     * @param $id
     * @return mixed
     */
    public function delete($id){
        return $this->shareModel->where(array('id'=>$id))->delete();
    }


    /**
     * 修改信息
     * @param $where
     * @param $save
     * @return bool
     */
    public function saveInfo($where,$save){
        return $this->shareModel->where($where)->save($save);
    }

    /**
     * 查询总数
     * @param $where
     * @return mixed
     */
    public function getShareCount($where){
        return $this->shareModel->where($where)->count();
    }



    /**
     * 新增列表
     * @param $where
     * @return mixed
     */
    public function shareType ($where=array()){
        return $this->shareTypeModel->where($where)->select();//->add($add);
    }

    /**
     * 新增列表
     * @param $where
     * @param $save
     * @return mixed
     */
    public function saveShareType ($where,$save){
        return $this->shareTypeModel->where($where)->save($save);//->add($add);;
    }

    /**
     * 新增列表
     * @param $add
     * @return mixed
     */
    public function addShareType($add){
        return $this->shareTypeModel->add($add);
    }

    public function delShareType($id){
        return $this->shareTypeModel->where((array('type_id'=>$id)))->delete();
    }

}